import pymysql

# cursorclass=pymysql.cursors.DictCursor更换游标的类型
def main():
    connect = pymysql.connect(host="39.107.245.102", port=3306, user="root", passwd="wuji5201314.", db="school",
                              charset="utf8",cursorclass=pymysql.cursors.DictCursor)
    try:
        with connect.cursor() as cursor:
            # 查询语句不进行赋值
            cursor.execute("select stu_id,stu_name,stu_stuaddr from tb_student")
            for row in cursor.fetchall():
                print(row['stu_id'],end='\t')
                print(row['stu_name'], end='\t')
                print(row['stu_stuaddr'])
    except pymysql.MySQLError as error:
        print('查询失败.{}'.format(error))
    # finally:正常异常都执行，必须要释放资源
    finally:
        connect.close()
if __name__ == "__main__":
    main()